<?php

namespace catchAdmin\phone\model;

use catcher\exceptions\AlertErrorException;

class AgentBaoMing extends \catchAdmin\model\AgentBaoMing
{

    public function saveData($data)
    {
        if (!empty($data['wechat_user_id'])) {
            if ($this
                    ->where('type', $data['type'])
                    ->where('wechat_user_id', $data['wechat_user_id'])
                    ->count() > 0) {
                throw new AlertErrorException('不能重复报名');
            }
        } else {
            if ($this
                    ->where('type', $data['type'])
                    ->where('mobile', $data['mobile'])
                    ->count() > 0) {
                throw new AlertErrorException('不能重复报名');
            }
        }

        return $this->saveDataCC([
            'wechat_user_id' => $data['wechat_user_id'] ?? 0,
            'type'           => $data['type'],
            'realname'       => $data['realname'],
            'mobile'         => $data['mobile'],
        ]);
    }


    ######################################## 显示 ################################################

}
